//
//  MainFramingController.m
//  ios-supplier 框架首页
//
//  Created by feynmanyuan on 15/4/15.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "MainFramingController.h"
#import "OrderListController.h"
#import "StoreManageController.h"

@interface MainFramingController ()

@end

@implementation MainFramingController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tabBarController.delegate = self;
    
    UINavigationController *orderFlowController, *merchandiseManageController, *settlementController, *storeManageController;
    
    UIStoryboard *orderFlowStoryBoard = [UIStoryboard storyboardWithName:@"OrderFlow" bundle:nil];
    orderFlowController = (UINavigationController*)[orderFlowStoryBoard instantiateViewControllerWithIdentifier:@"OrderFlowFirst"];
    
//    UIStoryboard *orderConfirmStoryBoard = [UIStoryboard storyboardWithName:@"Settlement" bundle:nil];
//    merchandiseManageController = (UINavigationController*)[orderConfirmStoryBoard instantiateViewControllerWithIdentifier:@"SettlementFirst"];
    
    UIStoryboard *courierManagerStoryBoard = [UIStoryboard storyboardWithName:@"FirstMerchandiseManage" bundle:nil];
    settlementController = (UINavigationController*)[courierManagerStoryBoard instantiateViewControllerWithIdentifier:@"BigFirstMerchandiseManage"];
    
    UIStoryboard *moreStoryBoard = [UIStoryboard storyboardWithName:@"StoreManage" bundle:nil];
    storeManageController = (UINavigationController*)[moreStoryBoard instantiateViewControllerWithIdentifier:@"StoreManageFirst"];
    
    UITabBarItem* items0 = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"dingdan-icon-nor"] tag:0];
    [items0 setImage:[UIImage imageNamed:@"dingdan-icon-nor"]];
    [items0 setSelectedImage:[UIImage imageNamed:@"dingan-sel"]];
    items0.imageInsets = UIEdgeInsetsMake(7, 0, -7, 0);
    
//    UITabBarItem* items1 = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"tongji-icon-nor"] tag:1];
//    [items1 setImage:[UIImage imageNamed:@"tongji-icon-nor"]];
//    [items1 setSelectedImage:[UIImage imageNamed:@"tongji-sel"]];
//    items1.imageInsets = UIEdgeInsetsMake(7, 0, -7, 0);
    
    UITabBarItem* items2 = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"guanli-icon"] tag:2];
    [items2 setImage:[UIImage imageNamed:@"guanli-icon"]];
    [items2 setSelectedImage:[UIImage imageNamed:@"guanli-icon-sel"]];
    items2.imageInsets = UIEdgeInsetsMake(7, 0, -7, 0);
    
    UITabBarItem* items3 = [[UITabBarItem alloc] initWithTitle:nil image:[UIImage imageNamed:@"dianpu-icon-nor"] tag:3];
    [items3 setImage:[UIImage imageNamed:@"dianpu-icon-nor"]];
    [items3 setSelectedImage:[UIImage imageNamed:@"dianpu-sel"]];
    items3.imageInsets = UIEdgeInsetsMake(7, 0, -7, 0);
    
    //关联各Controller和tabbaritem
    [orderFlowController setTabBarItem:items0];
//    [merchandiseManageController setTabBarItem:items1];
    [settlementController setTabBarItem:items2];
    [storeManageController setTabBarItem:items3];
    
    self.tabBarController.delegate = self;
    self.delegate = self;
    //添加关联
//    [self setViewControllers:[NSArray arrayWithObjects:orderFlowController, merchandiseManageController, settlementController, storeManageController, nil] animated:YES];
    [self setViewControllers:[NSArray arrayWithObjects:orderFlowController, settlementController, storeManageController, nil] animated:YES];
    
//    [self.tabBar setBackgroundImage:[UIImage imageNamed:@"pattern_toolbar"]];
    
    //适配IOS7+的edgesForExtendedLayout布局，背景不透明
    [self.tabBar setTranslucent:NO];
    [self setSelectedIndex:0];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

////此处处理delegate，是为了同步刷新店铺的营业状态（此处产品不应如此设计）
//- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
//    // 只在店铺状态标记为已改变的情况下才刷新页面
//    if( [JFBGlobalSetting getSetting].isStoreStateChange ){
//        if([viewController isKindOfClass:[UINavigationController class]] && [((UINavigationController*)viewController).topViewController isKindOfClass:[OrderListController class] ]) {
//            [((OrderListController*)((UINavigationController*)viewController).topViewController) reload:nil];
//        } else if([viewController isKindOfClass:[UINavigationController class]] && [((UINavigationController*)viewController).topViewController isKindOfClass:[StoreManageController class] ]) {
//            [((StoreManageController*)((UINavigationController*)viewController).topViewController) reload:nil];
//        }
//    }
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
